package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.dto.AddLinkDto;
import com.sangeng.domain.vo.LinkVo;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.service.LinkService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/content/link")
@RestController
@RequiredArgsConstructor
public class LinkController {
    private final LinkService linkService;

    @GetMapping("/list")
    public ResponseResult<PageVo> getLinkList(Integer pageNum, Integer pageSize, String name, String status) {
        return linkService.getLinkList(pageNum, pageSize, name, status);
    }

    //新增友链
    @PostMapping
    public ResponseResult<String> addLink(@RequestBody @Validated AddLinkDto linkDto) {
        return linkService.addLink(linkDto);
    }
    
    //修改友链
    @GetMapping("/{id}")
    public ResponseResult<LinkVo>  getLink(@PathVariable Long id) {
        return linkService.getLinkById(id);
    }
    @PutMapping
    public ResponseResult<String> updateLink(@RequestBody LinkVo link) {
        return linkService.updateLink(link);
    }

    @DeleteMapping("/{idList}")
    public ResponseResult<String> deleteLink(@PathVariable List<Long> idList) {
        return linkService.deleteLinkById(idList);
    }
}